package logic

import (
	"context"
	"errors"
	"home-mgr-sys/models/mysql"

	"home-mgr-sys/homerpc/homerpc"
	"home-mgr-sys/homerpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type HomeShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHomeShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HomeShowLogic {
	return &HomeShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *HomeShowLogic) HomeShow(in *homerpc.HomeShowRequest) (*homerpc.HomeShowResponse, error) {
	// todo: add your logic here and delete this line
	var home mysql.Home
	err := home.HomeShow(mysql.DB, in.HomesId)
	if err != nil {
		return nil, errors.New("储蓄失败")
	}
	return &homerpc.HomeShowResponse{
		Title:   home.Title,
		Address: home.Address,
		Price:   float32(home.Price),
	}, nil
}
